<?php
/**
 *@name 返回友好的时刻和日期
 *@param datetime $date  时间格式
 *@return
 * 几秒前，几分钟前，几小时前，几天前，周前，06-25，2012-07-05
 */
function to_friend_time($date) {
	if (is_null($date)) return '';
	date_default_timezone_set('Asia/Shanghai');
	$diff = time()-strtotime($date);
	
	if ($diff<60){
		return "约{$diff}秒前";
	}
	 
	$diff = round($diff/60);
	if ($diff<60){
		return "约{$diff}分钟前";
	}
	 
	$diff = round($diff/60);
	if ($diff<24){
		return "约{$diff}小时前";
	}
	
	/*
	$diff = round($diff/24);
	if ($diff<7){
		return $diff . "天前";
	}
	 
	$week_diff = round($diff/7);
	if ($week_diff<4){
		return $week_diff . "周前";
	}
	 
	$diff=round($diff/30);
	if($diff<12){
		return date('m-d', strtotime($date));
	}
	*/
	return date('Y-m-d', strtotime($date));
}
?>